home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_02 / ED-157 / envir_subs.c < prev    next >
C/C++ Source or Header  |  1993-09-10  |  2KB  |  83 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17. #include "opsys.h"
  18.  
  19. #include <stdlib.h>
  20. #include <string.h>
  21.  
  22. #include "memory.h"
  23. #include "ctyp_dec.h"
  24.  
  25. /******************************************************************************\
  26. |Routine: envir_subs
  27. |Callby: command init_term journal load_file main match_search parse_fnm wincom
  28. |Purpose: Translates strings containing environment variables. Returns a pointer to the translation.
  29. |Arguments:
  30. |    file is the string that may contain vars.
  31. \******************************************************************************/
  32. void envir_subs(file)
  33. char *file;
  34. {
  35. #ifndef VMS
  36.     Char temp[512],envbuf[512],*a,*aa,*b,c,*e;
  37.     
  38. /* move the string, translating environment variables found there */
  39.     memset(temp,0,sizeof(temp));
  40.     for(a = file,b = temp;(c = *a++);)
  41.     {
  42.         if(c == '$')
  43.         {
  44.             for(e = envbuf,aa = a;isalnum(*aa) || *aa == '_';*e++ = *aa++);
  45.             *e = '\0';
  46.             if((e = getenv(envbuf)))
  47.             {
  48.                 strcpy(b,e);
  49.                 b += strlen(e);
  50.                 a = aa;
  51.             }
  52.             else
  53.             {
  54.                 for(e = envbuf;*e;e++)
  55.                     *e = toupper(*e);
  56.                 if((e = getenv(envbuf)))
  57.                 {
  58.                     strcpy(b,e);
  59.                     b += strlen(e);
  60.                     a = aa;
  61.                 }
  62.                 else
  63.                     *b++ = c;
  64.             }
  65.         }
  66.         else if(c == '~')
  67.         {
  68.             if((e = getenv("HOME")))
  69.             {
  70.                 strcpy(b,e);
  71.                 b += strlen(e);
  72.             }
  73.             else
  74.                 *b++ = '~';
  75.         }
  76.         else
  77.             *b++ = c;
  78.     }
  79.     strcpy(file,temp);
  80. #endif
  81. }
  82.  
  83.